Option Strict Off
Option Explicit On
Friend Class SubmitForm
	Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "
	Public Sub New()
		MyBase.New()
		If m_vb6FormDefInstance Is Nothing Then
			If m_InitializingDefInstance Then
				m_vb6FormDefInstance = Me
			Else
				Try 
					'For the start-up form, the first instance created is the default instance.
					If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
						m_vb6FormDefInstance = Me
					End If
				Catch
				End Try
			End If
		End If
		'This call is required by the Windows Form Designer.
		InitializeComponent()
	End Sub
	'Form overrides dispose to clean up the component list.
	Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
		If Disposing Then
			If Not components Is Nothing Then
				components.Dispose()
			End If
		End If
		MyBase.Dispose(Disposing)
	End Sub
	'Required by the Windows Form Designer
	Private components As System.ComponentModel.IContainer
	Public ToolTip1 As System.Windows.Forms.ToolTip
	Public WithEvents Description As System.Windows.Forms.TextBox
	Public WithEvents cmdClose As System.Windows.Forms.Button
	Public WithEvents cmdSubmit As System.Windows.Forms.Button
	Public WithEvents Files As System.Windows.Forms.CheckedListBox
	Public WithEvents _Label1_1 As System.Windows.Forms.Label
	Public WithEvents _Label1_0 As System.Windows.Forms.Label
	Public WithEvents Label1 As Microsoft.VisualBasic.Compatibility.VB6.LabelArray
	'NOTE: The following procedure is required by the Windows Form Designer
	'It can be modified using the Windows Form Designer.
	'Do not modify it using the code editor.
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.Description = New System.Windows.Forms.TextBox()
        Me.cmdClose = New System.Windows.Forms.Button()
        Me.cmdSubmit = New System.Windows.Forms.Button()
        Me.Files = New System.Windows.Forms.CheckedListBox()
        Me._Label1_1 = New System.Windows.Forms.Label()
        Me._Label1_0 = New System.Windows.Forms.Label()
        Me.Label1 = New Microsoft.VisualBasic.Compatibility.VB6.LabelArray(Me.components)
        CType(Me.Label1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Description
        '
        Me.Description.AcceptsReturn = True
        Me.Description.AutoSize = False
        Me.Description.BackColor = System.Drawing.SystemColors.Window
        Me.Description.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.Description.ForeColor = System.Drawing.SystemColors.WindowText
        Me.Description.Location = New System.Drawing.Point(88, 16)
        Me.Description.MaxLength = 0
        Me.Description.Name = "Description"
        Me.Description.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Description.Size = New System.Drawing.Size(489, 105)
        Me.Description.TabIndex = 4
        Me.Description.Text = "Description"
        '
        'cmdClose
        '
        Me.cmdClose.BackColor = System.Drawing.SystemColors.Control
        Me.cmdClose.Cursor = System.Windows.Forms.Cursors.Default
        Me.cmdClose.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.cmdClose.ForeColor = System.Drawing.SystemColors.ControlText
        Me.cmdClose.Location = New System.Drawing.Point(312, 288)
        Me.cmdClose.Name = "cmdClose"
        Me.cmdClose.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cmdClose.Size = New System.Drawing.Size(97, 33)
        Me.cmdClose.TabIndex = 3
        Me.cmdClose.Text = "Cancel"
        '
        'cmdSubmit
        '
        Me.cmdSubmit.BackColor = System.Drawing.SystemColors.Control
        Me.cmdSubmit.Cursor = System.Windows.Forms.Cursors.Default
        Me.cmdSubmit.ForeColor = System.Drawing.SystemColors.ControlText
        Me.cmdSubmit.Location = New System.Drawing.Point(200, 288)
        Me.cmdSubmit.Name = "cmdSubmit"
        Me.cmdSubmit.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cmdSubmit.Size = New System.Drawing.Size(97, 33)
        Me.cmdSubmit.TabIndex = 2
        Me.cmdSubmit.Text = "&Submit"
        '
        'Files
        '
        Me.Files.BackColor = System.Drawing.SystemColors.Window
        Me.Files.Cursor = System.Windows.Forms.Cursors.Default
        Me.Files.ForeColor = System.Drawing.SystemColors.WindowText
        Me.Files.Items.AddRange(New Object() {"Files"})
        Me.Files.Location = New System.Drawing.Point(88, 136)
        Me.Files.Name = "Files"
        Me.Files.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Files.Size = New System.Drawing.Size(489, 139)
        Me.Files.TabIndex = 0
        '
        '_Label1_1
        '
        Me._Label1_1.BackColor = System.Drawing.SystemColors.Control
        Me._Label1_1.Cursor = System.Windows.Forms.Cursors.Default
        Me._Label1_1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label1.SetIndex(Me._Label1_1, CType(1, Short))
        Me._Label1_1.Location = New System.Drawing.Point(8, 16)
        Me._Label1_1.Name = "_Label1_1"
        Me._Label1_1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me._Label1_1.Size = New System.Drawing.Size(65, 25)
        Me._Label1_1.TabIndex = 5
        Me._Label1_1.Text = "Description:"
        Me._Label1_1.TextAlign = System.Drawing.ContentAlignment.TopRight
        '
        '_Label1_0
        '
        Me._Label1_0.BackColor = System.Drawing.SystemColors.Control
        Me._Label1_0.Cursor = System.Windows.Forms.Cursors.Default
        Me._Label1_0.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label1.SetIndex(Me._Label1_0, CType(0, Short))
        Me._Label1_0.Location = New System.Drawing.Point(8, 136)
        Me._Label1_0.Name = "_Label1_0"
        Me._Label1_0.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me._Label1_0.Size = New System.Drawing.Size(65, 25)
        Me._Label1_0.TabIndex = 1
        Me._Label1_0.Text = "Files:"
        Me._Label1_0.TextAlign = System.Drawing.ContentAlignment.TopRight
        '
        'SubmitForm
        '
        Me.AcceptButton = Me.cmdSubmit
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.CancelButton = Me.cmdClose
        Me.ClientSize = New System.Drawing.Size(626, 334)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Description, Me.cmdClose, Me.cmdSubmit, Me.Files, Me._Label1_1, Me._Label1_0})
        Me.Location = New System.Drawing.Point(4, 30)
        Me.Name = "SubmitForm"
        Me.Text = "Submit"
        CType(Me.Label1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub
#End Region 
#Region "Upgrade Support "
	Private Shared m_vb6FormDefInstance As SubmitForm
	Private Shared m_InitializingDefInstance As Boolean
	Public Shared Property DefInstance() As SubmitForm
		Get
			If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
				m_InitializingDefInstance = True
				m_vb6FormDefInstance = New SubmitForm()
				m_InitializingDefInstance = False
			End If
			DefInstance = m_vb6FormDefInstance
		End Get
		Set
			m_vb6FormDefInstance = Value
		End Set
	End Property
#End Region 
	
	'*******************************************************************************
	'
	' Copyright (c) 2003, Robert Cowham and Vaccaperna Systems Ltd.  All rights reserved.
	'
	' Redistribution and use in source and binary forms, with or without
	' modification, are permitted provided that the following conditions are met:
	'
	' 1.  Redistributions of source code must retain the above copyright
	'     notice, this list of conditions and the following disclaimer.
	'
	' 2.  Redistributions in binary form must reproduce the above copyright
	'     notice, this list of conditions and the following disclaimer in the
	'     documentation and/or other materials provided with the distribution.
	'
	' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
	' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
	' IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
	' ARE DISCLAIMED. IN NO EVENT SHALL VACCAPERNA SYSTEMS LTD. BE LIABLE FOR ANY
	' DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
	' (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
	' LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
	' ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
	' (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
	' SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
	'
	' *******************************************************************************
	'
	' Name:     SubmitForm.frm
	'
	' Author:   Robert Cowham <robert@vaccaperna.co.uk>
	'
	' Description:
	'   Show how to execute a command such as "change -o" and then "submit -i"
	'   and allow the user to manipulate things in between.
	'
	'   Note there job lists available etc (ignored in this demo).
	'
	'   No error handling!
	' ******************************************************************************
	
    Dim m_p4 As P4COM.p4
    Dim m_Files() As String
    Dim OutputArr() As String
    Dim ErrorArr() As String

    Public Sub DoSubmit(ByRef p As P4COM.p4)
        Dim i As Short

        ' Demonstrates how to handle commands which take -o and -i flags,
        ' in this case "change -o" and "submit -i" to commit the results.

        ' Copy environment since we want to set ParseForms on for this connection
        m_p4 = New P4COM.p4()
        m_p4.Charset = p.Charset
        m_p4.Client = p.Client
        m_p4.Cwd = p.Cwd
        m_p4.Host = p.Host
        m_p4.Language = p.Language
        m_p4.Password = p.Password
        m_p4.Port = p.Port
        m_p4.User = p.User

        m_p4.ParseForms()
        m_p4.Connect()
        OutputArr = m_p4.run("change -o")

        Description.Text = m_p4.Var("Description") ' Simple string variable
        m_Files = m_p4.ArrayVar("Files") ' StringArray variable
        Files.Items.Clear()
        For i = LBound(m_Files) To UBound(m_Files)
            Files.Items.Add(m_Files(i))
        Next
        Me.ShowDialog()
        Me.Close()
    End Sub

    Private Sub cmdClose_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdClose.Click
        Me.Close()
    End Sub

    Private Sub cmdSubmit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSubmit.Click
        Dim i As Short
        Dim j As Short

        m_p4.Var("Description") = Description.Text ' Setting string var
        j = 0
        For i = 0 To Files.Items.Count - 1
            If Files.GetItemChecked(i) Then
                ReDim m_Files(j)
                m_Files(j) = VB6.GetItemString(Files, i)
                j = j + 1
            End If
        Next
        Dim s As String
        If j = 0 Then
            MsgBox("No files selected!")
        Else
            m_p4.ArrayVar("Files") = VB6.CopyArray(m_Files)
            OutputArr = m_p4.run("submit -i")
            ErrorArr = VB6.CopyArray(m_p4.Errors)

            s = Join(OutputArr, " ")
            s = s & vbCrLf & "Errors: " & Join(ErrorArr, " ")
            MsgBox(s)
        End If
        Me.Close()
    End Sub
End Class